package cn.ac.cintcm.dao;

import java.util.List;

import org.springframework.security.userdetails.UserDetails;
import org.springframework.security.userdetails.UsernameNotFoundException;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import cn.ac.cintcm.model.User;

/**
 * User Data Access Object (GenericDao) interface.
 *
 * @author <a href="mailto:matt@raibledesigns.com">Matt Raible</a>
 */
public interface UserDao extends GenericDao<User, Long> {

    /**
     * Gets users information based on login name.
     * @param username the user's username
     * @return userDetails populated userDetails object
     * @throws org.springframework.security.userdetails.UsernameNotFoundException thrown when user not found in database
     */
    @Transactional
    UserDetails loadUserByUsername(String username) throws UsernameNotFoundException;

    /**
     * Gets a list of users ordered by the uppercase version of their username.
     *
     * @return List populated list of users
     */
    List<User> getUsers();

    /**
     * Saves a user's information.
     * @param user the object to be saved
     * @return the persisted User object
     */
    User saveUser(User user);

    /**
     * Retrieves the password in DB for a user
     * @param username the user's username
     * @return the password in DB, if the user is already persisted
     */
    @Transactional(propagation = Propagation.NOT_SUPPORTED)
    String getUserPassword(String username);

    /**
     * Retrieves the password in DB for a user
     * @param id the user's id
     * @return the password in DB, if the user is already persisted
     */
    @Transactional(propagation = Propagation.NOT_SUPPORTED)
    String getUserPassword(Long id);
    /**
     * Retrieves the user who have therapy in a week.
     * @return
     */
	List<User> getRecentUser(Long userId);

	/**
	 * Retrieves the user who haven't been notifed and the formula has been empty.
	 * @return
	 */
	List<User> getAttentionUser(Long userId);
	
	/**
	 * Retrieves user by login name
	 * @param userName
	 * @return
	 */
	User get(String userName);
    
	/**
	 * Retrieves the users which fuzzy match with key in the character of name, user name, relative and memo
	 * @param key string used to match
	 * @return fuzzy mathed user. 
	 */
	List<User> search(String key, Long userId);
	
	List<User> search(String key);
	
	/**
	 * Retrieves the doctors 
	 * @return
	 */
	List<User> getDoctors();
	
	/**
	 * Retrieve the new registered doctor
	 * @return
	 */
	List<User> getNewDoctors();

	List<User> getPatiens(Long id);
	
}
